package org.lanplay.server.pages;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import org.apache.wicket.markup.html.WebPage;

import com.google.inject.Inject;
import com.google.inject.Provider;

public abstract class TransactionAwarePage extends WebPage {
	private static final long serialVersionUID = 1L;

	@Inject
	private Provider<EntityManager> emp;

	@Override
	protected void onAfterRender() {
		super.onAfterRender();
		EntityTransaction tx = emp.get().getTransaction();
		if (tx.isActive()) {
			if (tx.getRollbackOnly()) {
				tx.rollback();
			} else {
				tx.commit();
			}
		}
	}
}
